namespace Brjnk.GpxExplorer.WPF
{
    using System.Windows;
    using System.Windows.Controls;
    using Brjnk.GpxExplorer.ViewModel;

    /// <summary>
    /// </summary>
    public class ListItemTemplateSelector : DataTemplateSelector
    {
        public ListItemTemplateSelector()
        {
        }

        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            var type = item.GetType();
            var element = container as FrameworkElement;

            if (typeof(WaypointVM).IsAssignableFrom(type))
            {
                return element.FindResource("WaypointItemTemplate") as DataTemplate;
            }
            else if (typeof(RouteVM).IsAssignableFrom(type))
            {
                return element.FindResource("RouteItemTemplate") as DataTemplate;
            }
            if (typeof(TrackVM).IsAssignableFrom(type))
            {
                return element.FindResource("TrackItemTemplate") as DataTemplate;
            }
            return null;
        }
    }
}